package com.spic.business.train.trainUserAnswer.controller;

import com.spic.business.common.core.utils.poi.BusinessExcelUtil;
import com.spic.business.train.trainUserAnswer.domain.TrainUserAnswer;
import com.spic.business.train.trainUserAnswer.service.ITrainUserAnswerService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 用户考试答案Controller
 *
 * @author spic
 * @date 2021-10-15
 */
@RestController
@RequestMapping("/train/trainUserAnswer")
public class TrainUserAnswerController extends BaseController
{
    @Autowired
    private ITrainUserAnswerService trainUserAnswerService;

    /**
     * 查询用户考试答案列表
     */
    @PreAuthorize(hasPermi = "business/train:trainUserAnswer:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainUserAnswer trainUserAnswer)
    {
        startPage();
        List<TrainUserAnswer> list = trainUserAnswerService.selectTrainUserAnswerList(trainUserAnswer);
        return getDataTable(list);
    }

    /**
     * 导出用户考试答案列表
     */
    @PreAuthorize(hasPermi = "business/train:trainUserAnswer:export")
    @Log(title = "用户考试答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainUserAnswer trainUserAnswer) throws IOException
    {
        List<TrainUserAnswer> list = trainUserAnswerService.selectTrainUserAnswerList(trainUserAnswer);
        ExcelUtil<TrainUserAnswer> util = new BusinessExcelUtil<TrainUserAnswer>(TrainUserAnswer.class);
        util.exportExcel(response, list, "用户考试答案数据");
    }

    /**
     * 获取用户考试答案详细信息
     */
    @PreAuthorize(hasPermi = "business/train:trainUserAnswer:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(trainUserAnswerService.selectTrainUserAnswerById(id));
    }

    /**
     * 新增用户考试答案
     */
    @PreAuthorize(hasPermi = "business/train:trainUserAnswer:add")
    @Log(title = "用户考试答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainUserAnswer trainUserAnswer)
    {
        return toAjax(trainUserAnswerService.insertTrainUserAnswer(trainUserAnswer));
    }

    /**
     * 修改用户考试答案
     */
    @PreAuthorize(hasPermi = "business/train:trainUserAnswer:edit")
    @Log(title = "用户考试答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainUserAnswer trainUserAnswer)
    {
        return toAjax(trainUserAnswerService.updateTrainUserAnswer(trainUserAnswer));
    }

    /**
     * 删除用户考试答案
     */
    @PreAuthorize(hasPermi = "business/train:trainUserAnswer:remove")
    @Log(title = "用户考试答案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(trainUserAnswerService.deleteTrainUserAnswerByIds(ids));
    }
}
